package com.gs.api.project.video.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gs.api.core.Result;
import com.gs.api.project.video.entity.BzBaseinfo;
import com.gs.api.project.video.entity.BzConfig;
import com.gs.api.project.video.service.IBzBaseinfoService;
import com.gs.api.project.video.service.IBzConfigService;
import com.gs.api.project.video.service.VideoService;
import com.gs.api.util.video.parse.ParseUtil;
import com.gs.api.util.video.parse.douyin.DouyinApp;
import com.gs.api.util.video.parse.huoshan.HuoshanApp;
import com.gs.api.util.video.parse.kuaishou.KuaishouApp;
import com.gs.api.util.video.parse.pipixia.PiPiXiaApp;
import com.gs.api.util.video.parse.vo.VideoVo;
import com.gs.api.util.video.parse.weishi.WeishiApp;
import com.gs.api.util.video.parse.zuiyou.ZuiyouApp;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author guoyunfei on 2022/3/12 22:43
 * @className VideoParseController
 * @description TODO
 * @Version 1.0
 */

@RestController
@RequestMapping("{appid}/video")
public class VideoParseController {

    @Autowired
    private IBzConfigService iBzConfigService;

    @Autowired
    private IBzBaseinfoService baseinfoService;

    @Autowired
    private VideoService videoService;

    @RequestMapping(value = "parse",method = RequestMethod.POST)
    public Result videoParse(@RequestBody  VideoVo vv, @PathVariable String appid) throws IOException {

        if(StringUtils.isEmpty(vv.getUrl())){
            return Result.failure("请输入解析链接");
        }

        List<BzConfig> list = iBzConfigService.list(new QueryWrapper<BzConfig>().eq("type", "down_domain"));

        if(list.size() == 0){
            return Result.failure("下载地址配置错误");
        }

        Map<String,Object> result = new HashMap<>(16);

        result.put("downDomain",list);

        BzBaseinfo baseinfo = baseinfoService.getOne(new QueryWrapper<BzBaseinfo>().eq("appid", appid).last("limit 1"));
        result.put("baseInfo",baseinfo);

        VideoVo videoVo = videoService.getVideoVoInfo(vv);

        result.put("videoVo",videoVo);
        if(Objects.isNull(videoVo)) {
            return Result.failure("不支持该平台");
        }

        return Result.success(result);
    }



}
